// pages/goodsList/goodsList.js
import http from '../../utils/http';
var app = getApp();
var listTimer = null;

import { GetOrderStoreListApi } from '../../utils/newApi.js';


Page({
  /**
   * 页面的初始数据
   */
  data: {
    businessId:'',
    
    page:1,
    pageSize: 6,
    type:'积分权益',
    loadMore: false,
    isLastPage:false,
    goodsOrderList:[],

    activeIndex:0,
    navList: [
      {
        name: '积分权益',
        id: 3
      },
      {
        name: '会员订单',
        id: 1
      },
      {
        name: '团购订单',
        id: 2
      },
      
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      businessId: options.businessId
    })
    this.GetGoodsOrderList()
  },

  

  GetGoodsOrderList(){
    let that = this
    wx.showLoading()
    let data={
      page:that.data.page,
      pageSize: that.data.pageSize,
      pagination:true,
      storeId:that.data.businessId,
      orderType: that.data.type
    }
    // console.log(data,"datadatadata")
    GetOrderStoreListApi(data).then(res=>{
      wx.hideLoading()
      if(res.code==0){
         this.setData({
          goodsOrderList: that.data.goodsOrderList.concat(res.data.list),
          // loadMore: false,
          isLastPage:res.data.lastPage
        })
      }else{
        wx.showToast({
          title: res.message,
          icon:'none'
        })
      }
    })
    // http.post('/api/order/v1/goods/business', {
    //   page: that.data.page,
    //   pageSize: that.data.pageSize,
    //   sourceId: businessId,
    //   type: that.data.type
    // }).then(res => {
    //   wx.hideLoading()
    //   if (res.code === 200) {

    //     this.setData({
    //       goodsOrderList: this.data.goodsOrderList.concat(res.data.data),
    //       loadMore: false,
    //       isLastPage:res.data.is_last_page
    //     })

    //   } else {
    //     wx.showToast({
    //       title: res.message,
    //       icon:'none'
    //     })
    //   }
    // })
  },
  copyOrderNo(e){
    wx.setClipboardData({
      data: e.currentTarget.dataset.orderno,
      success (res) {
        // wx.getClipboardData({
        //   success (res) {
        //     console.log(res.data) // data
        //   }
        // })
      }
    })
  },

  // 切换tab
  selectview(e){
    this.setData({
      activeIndex: e.currentTarget.dataset.index,
      goodsOrderList:[],
      page: 1,
      type:String(e.currentTarget.dataset.name),
    })
    this.GetGoodsOrderList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

    let page = this.data.page
    // console.log(this.data.isLastPage,"this.data.isLastPage")
    if (!this.data.isLastPage) {
      page++
      this.setData({
        page
      })
      // console.log(page,"page")
      this.GetGoodsOrderList()
    }
    
  },
})